import API from '../../api/movies/api_movies';
// import * as echarts from 'echarts'
export default {
	data() {
		return {
			moviesTypeCheckedArr: ["家庭"],
			moviesAreaCheckedArr: ["美国"],
			moviesTypeArr: [{
					"name": "家庭"
				},
				{
					"name": "歌舞"
				},
				{
					"name": "西部"
				},
				{
					"name": "荒诞"
				},
				{
					"name": "同性"
				},
				{
					"name": "爱情"
				},
				{
					"name": "古装"
				},
				{
					"name": "戏曲"
				},
				{
					"name": "黑色电影"
				},
				{
					"name": "儿童"
				},
				{
					"name": "奇幻"
				},
				{
					"name": "动画"
				},
				{
					"name": "科幻"
				},
				{
					"name": "武侠"
				},
				{
					"name": "脱口秀"
				},
				{
					"name": "短片"
				},
				{
					"name": "历史"
				},
				{
					"name": "悬疑"
				},
				{
					"name": "运动"
				},
				{
					"name": "动作"
				},
				{
					"name": "情色"
				},
				{
					"name": "音乐"
				},
				{
					"name": "真人秀"
				},
				{
					"name": "犯罪"
				},
				{
					"name": "冒险"
				},
				{
					"name": "战争"
				},
				{
					"name": "纪录片"
				},
				{
					"name": "惊悚"
				},
				{
					"name": "剧情"
				},
				{
					"name": "传记"
				},
				{
					"name": "灾难"
				},
				{
					"name": "恐怖"
				},
				{
					"name": "喜剧"
				}
			],
			moviesAreaArr: [{
					"name": "约旦"
				},
				{
					"name": "阿根廷"
				},
				{
					"name": "丹麦"
				},
				{
					"name": "韩国"
				},
				{
					"name": "中国香港"
				},
				{
					"name": "匈牙利"
				},
				{
					"name": "爱沙尼亚"
				},
				{
					"name": "西班牙"
				},
				{
					"name": "阿富汗"
				},
				{
					"name": "捷克"
				},
				{
					"name": "摩纳哥"
				},
				{
					"name": "美国"
				},
				{
					"name": "斯洛文尼亚"
				},
				{
					"name": "捷克斯洛伐克"
				},
				{
					"name": "波兰"
				},
				{
					"name": "西德"
				},
				{
					"name": "比利时"
				},
				{
					"name": "中国大陆"
				},
				{
					"name": "土耳其"
				},
				{
					"name": "墨西哥"
				},
				{
					"name": "芬兰"
				},
				{
					"name": "秘鲁"
				},
				{
					"name": "黎巴嫩"
				},
				{
					"name": "伊朗"
				},
				{
					"name": "博茨瓦纳"
				},
				{
					"name": "卢森堡"
				},
				{
					"name": "阿联酋"
				},
				{
					"name": "阿尔及利亚"
				},
				{
					"name": "瑞典"
				},
				{
					"name": "法国"
				},
				{
					"name": "印度尼西亚"
				},
				{
					"name": "摩洛哥"
				},
				{
					"name": "俄罗斯"
				},
				{
					"name": "塞尔维亚"
				},
				{
					"name": "巴哈马"
				},
				{
					"name": "白俄罗斯"
				},
				{
					"name": "塞内加尔"
				},
				{
					"name": "泰国"
				},
				{
					"name": "越南"
				},
				{
					"name": "澳大利亚"
				},
				{
					"name": "巴西"
				},
				{
					"name": "希腊"
				},
				{
					"name": "意大利"
				},
				{
					"name": "新加坡"
				},
				{
					"name": "马来西亚"
				},
				{
					"name": "荷兰"
				},
				{
					"name": "南斯拉夫"
				},
				{
					"name": "日本"
				},
				{
					"name": "瑞士"
				},
				{
					"name": "中国澳门"
				},
				{
					"name": "爱尔兰"
				},
				{
					"name": "塞浦路斯"
				},
				{
					"name": "葡萄牙"
				},
				{
					"name": "保加利亚"
				},
				{
					"name": "苏联"
				},
				{
					"name": "卡塔尔"
				},
				{
					"name": "古巴"
				},
				{
					"name": "马耳他"
				},
				{
					"name": "英国"
				},
				{
					"name": "挪威"
				},
				{
					"name": "南非"
				},
				{
					"name": "东德"
				},
				{
					"name": "委内瑞拉"
				},
				{
					"name": "新西兰"
				},
				{
					"name": "奥地利"
				},
				{
					"name": "罗马尼亚"
				},
				{
					"name": "德国"
				},
				{
					"name": "中国"
				},
				{
					"name": "印度"
				},
				{
					"name": "巴基斯坦"
				},
				{
					"name": "加拿大"
				},
				{
					"name": "中国台湾"
				}
			],
			movieArr: [],
			orderBy: 0,
			total: 10,
			pageNum: 1,
			pageSize: 20
		};
	},
	created() {},
	methods: {
		toBigScreen() {
			let that = this;
			let routeData = that.$router.resolve({
				name: 'bigScreen'
			});
			window.open(routeData.href, '_blank');
		},
		toMovieList() {
			let that = this;
			that.$router.push({
				name: 'movieList'
			})
		},
		toDataOverview() {
			let that = this;
			that.$router.push({
				name: 'dataOverview'
			})
		},
		initSearch() {
			let that = this;
			API.getMoviesScore({}).then(
				function(r) {
					if (r && r.code === 200) {
						let datas = r.content;
						movieArr = [];

					} else {
						that.$Message.error(r.message);
					}
				},
				function(err) {
					that.$Message.error(err.toString());
				}
			);
		},
		moviesTypeCheckedChange() {
			let that = this;
			if (that.moviesTypeCheckedArr.length > 1) {
				that.moviesTypeCheckedArr = [that.moviesTypeCheckedArr[1]]
			}

			console.log(that.moviesTypeCheckedArr)
			this.getMoviesByConditions();
		},
		moviesAreaCheckedChange() {
			let that = this;
			if (that.moviesAreaCheckedArr.length > 1) {
				that.moviesAreaCheckedArr = [that.moviesAreaCheckedArr[1]]
			}
			console.log(that.moviesAreaCheckedArr)
			this.getMoviesByConditions();
		},
		pageChange(page){
			// console.log(page)
			this.pageNum = page
			this.getMoviesByConditions()
		},

		getMoviesByConditions() {
			this.$forceUpdate();
			let that = this;
			API.getMovies({
				types: that.moviesTypeCheckedArr,
				locations: that.moviesAreaCheckedArr,
				pageNum: that.pageNum - 1,
				pageSize: that.pageSize,
				orderBy: that.orderBy
			}).then(
				function(r) {
					if (r && r.code === 200) {
						that.movieArr = r.content.content;
						that.total = that.movieArr.length;

					} else {
						that.$Message.error(r.message);
					}
				},
				function(err) {
					that.$Message.error(err.toString());
				}
			);
		},
	},
	mounted() {
		this.getMoviesByConditions();
	}
};